<template>
  <BaseMainSlot>
    <template v-slot:searchbox>
      <el-collapse v-model="activeName" accordion @change="handleChange">
        <el-collapse-item name="1">
          <template slot="title">
            <div class="select-btns search-btns" @click.stop="changeSelect()">
              <i class="el-icon-circle-check"></i>
              <p v-if="activeName==='1'">收起筛选</p>
              <p v-if="activeName===''">展开筛选</p>
            </div>
          </template>
          <div class="search-btn search-btns" @click.stop="queryPageList()">
            <i class="el-icon-circle-check"></i>
            <p>查询</p>
          </div>
          <div class="select-box-content">
            <div class="select-box-content-name">鱼塘名称</div>
            <el-input v-model="pondName" clearable />
          </div>
        </el-collapse-item>
      </el-collapse>
    </template>
    <template v-slot:btnsBar>
      <ActionBar
        :add-active="addActive"
        :del-active="delActive"
        :page-no="163"
        @add="add"
        @del="del"
      />
    </template>
    <template v-slot:content>
      <el-table
        ref="tableData"
        v-loading="loading"
        highlight-current-row
        :data="tableData"
        stripe
        border
        height="calc(100% - 50px)"
        :row-key="
          row => {
            return row.hangExposedNetStandardId;
          }
        "
        @selection-change="handleSelectionChange"
        @select="select"
        @select-all="selectAll"
      >
        <el-table-column type="selection" width="55" :reserve-selection="true" :selectable="(row) => { return !row.selectable }" />
        <el-table-column type="index" label="序号" width="50">
          <template slot-scope="scoped">
            {{ scoped.row.hangExposedNetStandardId?scoped.$index+1:'' }}
          </template>
        </el-table-column>
        <el-table-column prop="position" label="位置" />
        <el-table-column prop="season" label="季节" >
          <!-- <template v-if="scoped.row.maxRate!==undefined" slot-scope="scoped">
            {{ scoped.row.maxRate+ '%'}}
          </template> -->
        </el-table-column>
        <el-table-column prop="workType" label="作业类型" >
          <!-- <template v-if="scoped.row.minRate!==undefined" slot-scope="scoped">
            {{ scoped.row.minRate+ '%'}}
          </template> -->
        </el-table-column>
        <el-table-column prop="duration" label="作业时长" >
          <!-- <template v-if="scoped.row.minRate!==undefined" slot-scope="scoped">
            {{ scoped.row.minRate+ '%'}}
          </template> -->
        </el-table-column>
        <el-table-column label="操作" width="250">
          <template v-if="scoped.row.hangExposedNetStandardId" slot-scope="scoped">
            <div class="table-btns-box">
              <div class="table-btns edit-btns" @click="edit(scoped.row)">
              <!-- <div class="table-btns edit-btns" @click="edit(scoped.row)"  v-if="judgePermission(163,'edit')"> -->
                <p>修改</p>
              </div>
              <div class="table-btns del-btns" @click="delOne(scoped.row)">
              <!-- <div class="table-btns del-btns" @click="delOne(scoped.row)"  v-if="judgePermission(163,'deleteone')"> -->
                <p>删除</p>
              </div>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <Pagination
        :page-size="pageSize"
        :current-page="currentPage"
        :total-size="totalSize"
        @changePageSize="changePageSize"
        @changeCurrentPage="changeCurrentPage"
      />
      <AddEditDialog
        ref="addEditDialog"
        :now-chance-stau="nowChanceStau"
        :title-text="titleText"
        :edit-object="editObject"
        :show.sync="showAddEditDialog"
        @closeDialog="closeDialog"
        @cancelDialog="cancel"
      />
    </template>
  </BaseMainSlot>
</template>

<script>
import ActionBar from "@/components/ActionBar";
import Pagination from "@/components/Pagination";
import BaseMainSlot from "@/components/BaseMainSlot/kong-new2.vue";
import AddEditDialog from "./components/add-edit-dialog.vue";
import { mymixin } from "@/utils/mixin";
import { mapGetters } from 'vuex';

import NetStandardApi from "@/api/operation-management/hang-exposed-net-standard"
export default {
  name: 'FishPondManage',
  components: { ActionBar, Pagination, BaseMainSlot, AddEditDialog },
  mixins: [mymixin],
  data() {
    return {
      // 查询条件：鱼塘名称
      pondName: "",
      checkedIdList: []
    };
  },
  computed: {
    ...mapGetters({
      judgePermission: "permission/judgePermission"
    })
  },
  watch: {},
  created() {
    this.queryPageList();
  },
  mounted() {
  },
  methods: {
    queryPageList() {
      let params = {
        page: this.currentPage,
        size: this.pageSize,
        entity: {
        }
      };
      NetStandardApi.queryPageByCondition(params).then(res => {
        if (res.success === true) {
          let data = res.data || {};
          this.totalSize = data.totalElements;
          // 赋值数组
          this.tableData = data.content;
          this.addblankmet();
          this.resetActionBar();
        }
      });
    },
    changePageSize(pageSize) {
      this.pageSize = pageSize;
      this.queryPageList();
    },
    changeCurrentPage(currentPage) {
      this.currentPage = currentPage;
      this.queryPageList();
    },
    selectAll(list) {
      let notvalue = true
      list.forEach(item => {
        if (!item.hangExposedNetStandardId) {
          notvalue = false
        }
      });
      if (notvalue === false) {
        this.$message.warning("不可选择空数据！");
      }
    },
    select(list) {
      let notvalue = true
      list.forEach(item => {
        if (!item.hangExposedNetStandardId) {
          notvalue = false
        }
      });
      if (notvalue === false) {
        this.$message.warning("不可选择空数据！");
      }
    },
    handleSelectionChange(list) {
      this.checkedIdList = [];
      let notvalue = true
      let emptyList = []
      this.checkedIdList = list.map(item => {
        if (item.hangExposedNetStandardId) {
          return item.hangExposedNetStandardId
        } else {
          notvalue = false
          emptyList.push(item)
          return ""
        }
      });
      if (notvalue === false) {
        // this.$message.warning("不可选择空数据！");
        this.toggleNoSelection(emptyList)
        return
      }
      if (this.checkedIdList.length >= 1) this.delActive = true;
      else this.delActive = false;
    },
    // 表格删除
    delmessage() {
      NetStandardApi.delListById({ idList: this.checkedIdList }).then(res => {
        if (res.success) {
          this.$message.success("删除成功");
          this.queryPageList();
          this.resetActionBar();
        }
      });
    },
    // 单个删除
    delOne(data) {
      this.$confirm("此操作将永久删除该项, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        
      })
        .then(() => {
          NetStandardApi.delById({id:data.hangExposedNetStandardId}).then(res => {
            if (res.success === true) {
              this.$message.success("删除成功!");
              this.queryPageList();
              this.resetActionBar();
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    // 表格删除
    delmessage() {
      NetStandardApi.delListById({idList:this.checkedIdList}).then(res => {
        if (res.success) {
          this.$message.success(res.message);
          this.queryPageList();
          this.resetActionBar();
        }
      });
    },
    // 添加
    add() {
      this.nowChanceStau = 'add'
      this.titleText = "添加"
      this.addActive = false;
      this.delActive = false;
      this.showAddEditDialog = true
    },
    // 修改
    edit(row) {
      if (row.hangExposedNetStandardId) {
        this.editObject = JSON.parse(JSON.stringify(row));
        this.nowChanceStau = 'edit'
        this.titleText = "修改"
        this.addActive = false;
        this.delActive = false;
        this.showAddEditDialog = true
      } else {
        this.editObject = {}
      }
    }
  }
};
</script>

<style lang="scss" scoped>
</style>
